

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

typedef unsigned long (*pear_version_t)(void);
typedef int (*pear_main_t)(int argc, char *argv[]);

int main(void)
{
	// get function address
	//
	char *dl_lib_path = "./lib3rdapp/lib3rdapp.so";

	void *handle = dlopen(dl_lib_path, RTLD_NOW);

	if (NULL == handle) {
		printf("dlopen 0 %s\n", dlerror());
		exit(-1);
	}

	pear_version_t 	pear_version = dlsym(handle, "pear_version");
	pear_main_t 	pear_main = dlsym(handle, "pear_main");

	// version
	//
	printf("3rd app version: %lu\n", pear_version());

	// run 
	//
	#define ARGC 6
	char *argv[ARGC] = {
		"3rd_app", 
		"--mac=20:76:93:93:93:93",					// mac, you can use it as your node flag
		"--install_path=/", 						// option
		"--cache_path=/mnt/sda1/.pear/srv/3rd_app_cache_dir",		// you can store your cache data in ${cache_path}
		"--conf_path=/mnt/sda1/.pear/etc/3rd_app_conf_dir",		// you can store your config data in ${conf_path}
		"--log_path=/mnt/sda1/.pear/var/log/3rd_app_log_dir"		// you can store your log data in ${log_path}
	};

	pear_main(ARGC, argv);

	dlclose(handle);

	return 0;
}
